
//1297.子串的最大出现次数
class Solution {
    public:
        int maxFreq(string s, int maxLetters, int minSize, int maxSize) {
            //通过map来统计子字符串出现的次数
            unordered_map<string, int> m;
            int ch[26] = { 0 };   //统计字符的个数
            int right = 0, left = 0, n = s.size();
            int differ = 0;   //用来统计不同字符的个数
            int ret=0;       //返回值
            while (right < n)
            {
                //入窗口
                if (ch[s[right] - 'a'] == 0) differ++;
                ch[s[right++] - 'a']++;
    
                //调整答案
                if(right - left == minSize)  //长度满足条件进一步判断是否满足条件
                {
                    if(differ<=maxLetters) 
                    {
                        string tmp=s.substr(left,right-left);
                        m[tmp]++;
                        ret=max(ret,m[tmp]);
                    }
                    //出窗口
                    ch[s[left] - 'a']--;
                    if (ch[s[left] - 'a'] == 0) differ--;
                    left++;
                }
            }
            return ret;
        }
    };